/* 
 * Copyright 2014 ShangDao.Ltd  All rights reserved.
 * SiChuan ShangDao.Ltd PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * 
 * @MybaJoinAdapter.java  2014年9月11日 下午5:50:11 - Guzhu
 * @author Guzhu
 * @email:muyi126@163.com
 * @version 1.0
 */

package com.android.tiango.baba.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.scsd.tiango.R;
import com.android.tiango.baba.entity.BarModel;
import com.android.tiango.baba.util.ImageLoader;

public class MybaJoinAdapter extends BaseAdapter {
	private ArrayList<BarModel> list;
	private Context context;
	private ImageLoader mLoader;

	public MybaJoinAdapter(Context context, ArrayList<BarModel> list) {
		this.list = list;
		this.context = context;
	}

	public void setImageLoader(ImageLoader loader) {
		mLoader=loader;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.item_myba_join, null);
			viewHolder = new ViewHolder();
			viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
			viewHolder.tv_chengYuan = (TextView) convertView.findViewById(R.id.tv_chengYuan);
			viewHolder.tv_huati = (TextView) convertView.findViewById(R.id.tv_huati);
			viewHolder.bt_join = (Button) convertView.findViewById(R.id.bt_join);
			viewHolder.iv_header = (ImageView) convertView.findViewById(R.id.iv_header);

			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		BarModel bean = list.get(position);
		if (null != bean) {
			viewHolder.tv_title.setText(bean.getBarName());
			viewHolder.tv_chengYuan.setText(bean.getMemberNumber()+"");
			viewHolder.tv_huati.setText(bean.getTodayTopicNumber()+"");
			viewHolder.bt_join.setVisibility(View.INVISIBLE);
			if (null!=mLoader) {
				mLoader.loadImage(bean.getBarIcon(), viewHolder.iv_header);
			}
		}

		return convertView;
	}

	private class ViewHolder {
		private TextView tv_title;
		private TextView tv_chengYuan;
		private TextView tv_huati;
		private Button bt_join;
		private ImageView iv_header;
	}

}
